import { createStoreModule, Getter, Module, StoreModule } from '@/lib'
import { Action, Mutation } from '@/lib/decorator'
import store from '.'

@Module({ name: 'app', store })
class AppStore extends StoreModule {
  public token: string = '123'

  @Getter
  get tokenWithPrefix() {
    return `token is ${this.token}`
  }

  @Mutation
  SET_TOKEN(token: string) {
    this.token = token
  }

  @Action
  async asyncSetToken(token: string) {
    this.SET_TOKEN(
      await new Promise((resolve) => {
        setTimeout(() => {
          resolve(token)
        }, 1000)
      })
    )
  }
}

const useAppStore = createStoreModule(AppStore)
export default useAppStore
